<?php

    #-------------------------------------------------------------#
	# This file is part of the Tekuna MVC Microframework for PHP. #
	# (c) 2009 Niels Jäckel <niels.jaeckel@tekuna.org>            #
	# Please visit http://tekuna.org/ for more information.       #
	#                                                             #
	# This software is licensed under the MIT License. Please     #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#


	class AutoloadTest extends AbstractTekunaTestCase {


		public function testNonExistentClass() {

			// testing object creation of non-existent class
			try {

				new NonExistentClass();
				$this -> fail('ClassNotFoundException expected');
			}
			catch (ClassNotFoundException $e) {

				$this -> pass();
			}


			// testing dynamic object creation of non-existent class
			try {

				$sClass = 'NonExistentClass2';
				new $sClass();
				
				$this -> fail('ClassNotFoundException expected');
			}
			catch (ClassNotFoundException $e) {

				$this -> pass();
			}


			// testing object creation of non-existent class via eval()
			try {

				eval("new NonExistentClass3();");
				$this -> fail('ClassNotFoundException expected');
			}
			catch (ClassNotFoundException $e) {

				$this -> pass();
			}


			// testing class not found exception with class_exists()
			try {

				class_exists('NonExistentClass4');
				$this -> fail('ClassNotFoundException expected');
			}
			catch (ClassNotFoundException $e) {

				$this -> pass();
			}
			
			// call the function withoug such exception
			$this -> assertFalse(class_exists('NonExistentClass5', FALSE));
			
			
			// non-existent class via reflection
			try {

				new ReflectionClass('NonExistentClass6');
				$this -> fail('ClassNotFoundException expected');
			}
			catch (ClassNotFoundException $e) {

				$this -> pass();
			}
		}


		public function testNonExistentStaticClass() {

// This works only for PHP 5.2.x and not for PHP 5.3
//
//			// try static call on non-existent class
//			try {
//
//				NonExistentClass10 :: myFunction();
//				$this -> fail('ClassNotFoundException expected');
//			}
//			catch (ClassNotFoundException $e) {
//
//				$this -> pass();
//			}


			// try static call on non-existent class via call_user_func()
			try {

				call_user_func(array('NonExistentClass11', 'myFunction'));
				$this -> fail('ClassNotFoundException expected');
			}
			catch (ClassNotFoundException $e) {

				$this -> pass();
			}


// This works only for PHP 5.2.x and not for PHP 5.3
//
//			// try static call on non-existent class via eval();
//			try {
//
//				eval("NonExistentClass12 :: myFunction();");
//				$this -> fail('ClassNotFoundException expected');
//			}
//			catch (ClassNotFoundException $e) {
//
//				$this -> pass();
//			}
		}
	}
